package qmlt.evaluating;

import qmlt.dataset.DataSet;
import qmlt.dataset.Instance;
import qmlt.learning.Learner;

@SuppressWarnings("unchecked")
public class RegressionSquareErrorEvaluator<LearnerClass extends Learner>
implements Evaluator<LearnerClass>
{

    @Override
    public float evaluate(LearnerClass learner, DataSet testSet)
    {
        float se = 0;
        for (Instance inst : testSet.getInstances())
        {
            float pred = (Float) learner.predict(inst);
            float target = (Float) inst.getTarget();
            float d = pred - target;
            se += d * d;
        }
        return se;
    }

}
